home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
nt
/
we32i30d.zip
/
WEEXTSRC.ZI_
/
CTAGS.C
next >
Wrap
C/C++ Source or Header
|
1992-09-21
|
7KB
|
224 lines
/*------------------------------------------------------------------------*
* CTAGS.C - sample source for a GoToTag function. To use this *
* function, add a command/menu mapping to WE_EXT.RC, add *
* a case statement for the new command, and compile and *
* link this file with WE_EXT.C. *
* *
* The TAGS.EXE program shipped with WinEdit generates a *
* tag file in the correct format with the following *
* command line: *
* *
* TAGS -om -tWINEDIT.MRK filespec *
* *
*------------------------------------------------------------------------*/
#define STRICT
#define _WINDLL
#include <windows.h>
#include "we_ext.h"
#include "private.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
char gszTemp[16]; /* this needs to be in DGROUP for atoi() */
char gszFileName[256]; /* this needs to be in DGROUP for fopen() */
#define BUFSIZE 16383
/*------------------------------------------------------------------------*
* GoToTag() - retrieves the word at the caret and looks up the *
* tag in WINEDIT.MRK. If found, loads the appropriate *
* file and goes to that line. *
* *
* RETURNS: Nothing. *
* *
*------------------------------------------------------------------------*/
void GoToTag(HWND hWnd)
{
char szTemp[64];
char szLoadFile[256];
UINT uiLineNo;
edEditGetCurrentWord(hWnd,szTemp,63);
lstrcpy(gszFileName,"WINEDIT.MRK");
uiLineNo = FindToken(szTemp,szLoadFile);
if (uiLineNo)
{
if (edFileOpen(hWnd,szLoadFile))
edEditGoToLine(hWnd,uiLineNo);
}
}
/*------------------------------------------------------------------------*
* *
* FindToken() - find the token lpToken in lpTagFileName. *
* *
* RETURNS: Line number if found. 0 if not. *
* *
* The tag file must be in Microsoft format: TOKEN FILENAME(lineno). *
* *
* The TAGS.EXE program shipped with WinEdit generates a tag file *
* in the correct format with the following command line: *
* *
* TAGS -om -tWINEDIT.MRK filespec *
* *
*------------------------------------------------------------------------*/
UINT FindToken(LPSTR szToken, LPSTR lpLoadFileName)
{
int f;
int i;
char szNewFile[256];
UINT uiLineNo,uiRval;
OFSTRUCT of;
HANDLE hBuffer;
LPSTR lpBuffer;
LPSTR lpFoundIt;
LONG lFilePos;
uiLineNo = 0;
f = OpenFile(gszFileName,&of,OF_READ|OF_SHARE_DENY_NONE);
if (f == HFILE_ERROR)
return 0;
_fstrupr(szToken);
hBuffer = GlobalAlloc(GHND,BUFSIZE+1);
if (!hBuffer)
return 0;
lpBuffer = GlobalLock(hBuffer);
uiRval = _lread(f,lpBuffer,BUFSIZE);
_fstrupr(lpBuffer);
/* back up to the last CR/LF */
if (uiRval)
i = uiRval-1;
else
i = 0;
while (i && (lpBuffer[i] != 0x0D))
i--;
if (i)
{
i += 2;
_llseek(f,i,0);
lFilePos = uiRval = (UINT)i;
}
while (uiRval)
{
lpFoundIt = Scan(szToken,
lpBuffer,
uiRval);
if (lpFoundIt)
{
/* move to the file name */
for (;*lpFoundIt != ' ';lpFoundIt++);
lpFoundIt++;
/* build the file name */
for (i=0;(*lpFoundIt != ' ') && (*lpFoundIt != '(');i++,lpFoundIt++)
szNewFile[i] = *lpFoundIt;
szNewFile[i] = 0;
lpFoundIt++;
/* grab the line number */
for (i=0;(*lpFoundIt != ' ') && (*lpFoundIt != ')');i++,lpFoundIt++)
gszTemp[i] = *lpFoundIt;
gszTemp[i] = 0;
uiLineNo = atoi(gszTemp);
break;
}
else
{
uiRval = _lread(f,lpBuffer,BUFSIZE);
if (uiRval)
{
_fstrupr(lpBuffer);
/* back up to the last CR/LF */
i = uiRval-1;
while (i && (lpBuffer[i] != 0x0D))
i--;
if (i)
{
i += 2;
lFilePos += i;
_llseek(f,lFilePos,0);
uiRval = (UINT)i;
}
}
}
}
_lclose(f);
lstrcpy(lpLoadFileName,szNewFile);
return uiLineNo;
}
/*------------------------------------------------------------------------*
* Scan() - brute force buffer searcher. *
* *
* RETURNS: Pointer to matching string, NULL if not found. *
* *
*------------------------------------------------------------------------*/
LPSTR Scan(LPSTR lpPattern,
LPSTR lpText,
int iLength)
{
LPSTR lpNext;
LPSTR lpFound;
LPSTR lpTemp;
LPSTR lpCheckText;
char cFirstChar;
cFirstChar = lpPattern[0];
lpTemp = lpText;
/* search for the first character */
lpFound = lpNext = _fmemchr(lpTemp,cFirstChar,iLength);
while (lpNext)
{
/* check for a complete match */
for (lpCheckText = lpPattern;
*lpCheckText && *lpNext && (*lpCheckText == *lpNext);
*lpCheckText++,*lpNext++);
if (!(*lpCheckText))
/* we got a complete match */
return lpFound;
iLength -= (lpNext - lpTemp);
lpTemp = lpNext;
/* search for the next occurence of the first character */
if (iLength > 0)
lpFound = lpNext = _fmemchr(lpTemp,cFirstChar,iLength);
else
break;
}
return NULL;
}